package io.xiyou.order.service.support;

import io.xiyou.goods.api.bo.CreateOrderBO;
import io.xiyou.order.api.dto.OrderDTO;
import io.xiyou.order.dao.mapper.OrderMapper;
import io.xiyou.order.dao.model.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @ClassName：OrderSupport
 * @Author：西柚
 * @Date：2021/11/6 3:52 下午
 * @Versiion：1.0
 */
@Slf4j
@Service
public class OrderSupport {

    @Autowired
    private OrderMapper orderMapper;

    /**
     * 创建订单
     *
     * @param createOrderBO
     */
    public OrderDTO createOrder(CreateOrderBO createOrderBO) {
        Order order = new Order();
        BeanUtils.copyProperties(createOrderBO, order);
        order.setOrderStatus(1);
        order.setCreateDate(new Date());
        order.setDelFlag(0);

        orderMapper.insert(order);

        OrderDTO orderDTO = new OrderDTO();
        BeanUtils.copyProperties(order, orderDTO);

        return orderDTO;
    }

}
